package admin

import (
	"context"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductSkuListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductSkuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductSkuListLogic {
	return &ProductSkuListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductSkuListLogic) ProductSkuList(req *types.ProductSkuListReq) (resp []types.ProductSkuListResp, err error) {
	tx := utils.Db.Model(&models.ProductSku{}).Joins("LEFT JOIN products ON products.id = product_skus.product_id").Where("product_skus.product_id = ?", req.ProductID)
	tx = tx.Select("product_skus.*,products.name as product_name").Order("product_skus.id desc")
	resp = make([]types.ProductSkuListResp, 0)
	utils.TxFind(tx, &resp)
	return resp, nil
}
